package org.xteam.sled.semantic.exp;

public class ExpConst extends Exp {

	private int value;

	public ExpConst(int value) {
		this.value = value;
	}
	
	public int value() {
		return value;
	}
	
	public boolean isConst() {
		return true;
	}
	
	public int hashCode() {
		return value;
	}
	
	public boolean equals(Object o) {
		return (o instanceof ExpConst)
			&& ((ExpConst)o).value == value;
	}

	@Override
	protected TermList toTermList(boolean neg, TermList answers) {
		if (value != 0)
			answers.add(neg ? -value : value, new ExpConst(1));
		return answers;
	}

	@Override
	public void visit(IExpVisitor visitor) {
		visitor.visitConst(this);
	}
	
	public String toString() {
		return String.valueOf(value);
	}

}
